Skip to content

Conversation

@sugar700
Copy link

@sugar700 sugar700 commented Aug 9, 2019

This change is Reviewable

Fixes #247.

@sugar700 sugar700 force-pushed the implement-std-error branch from fbf6e37 to ff679e1 Compare August 9, 2019 09:09
}
}

impl<'i> Error for BasicParseError<'i> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you not implement description here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for Error says: "This method is soft-deprecated. Although using it won’t cause compilation warning, new code should use Display instead and new impls can omit it."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement it anyway, calling BasicParseErrorKind::description.

@dutchmartin
Copy link

@SimonSapin @nox Could someone take another look at this PR?
If there are any issues with it, please let me know.
I am happy to fix them since I want to use this error feature in my own project.

}
}

impl<'i> Error for BasicParseError<'i> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement it anyway, calling BasicParseErrorKind::description.


impl<'i> fmt::Display for BasicParseError<'i> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", self.kind.description())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't print enough information, i.e. we end up not printing the payloads of UnexpectedToken(_) and AtRuleInvalid(_).

Comment on lines +183 to +186
write!(formatter, "{}", match &self.kind {
ParseErrorKind::Basic(basic_kind) => basic_kind.description(),
ParseErrorKind::Custom(_) => "Custom error",
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the match outside and avoid write!.

match &self.kind {
    ParseErrorKind::Basic(basic) => basic.fmt(formatter),
    ParseErrorKind::Custom(_) => "custom error".fmt(formatter),
}

fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", match &self.kind {
ParseErrorKind::Basic(basic_kind) => basic_kind.description(),
ParseErrorKind::Custom(_) => "Custom error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the payload disregarded here?

}
}

impl<'i, T> Error for ParseError<'i, T> where T: fmt::Debug {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement description here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PasrseError and error Trait

3 participants